#include"DEMOGameState_Context.h"
#include"DEMOGameState_Base.h"

#include"DEMOTank_Trial.h"

#include<stdio.h>
#include<iostream>
using namespace std;



void DEMOGameState_Base::OnInit(DEMOGameState_Context* const ownerContext)
{
	m_context = ownerContext;
}

//	
//	Class DEMOGameState_Test1
//	
DEMOGameState_Test1::DEMOGameState_Test1()
{
	
}

DEMOGameState_Test1::~DEMOGameState_Test1()
{
	
}

void DEMOGameState_Test1::OnInit(DEMOGameState_Context* const ownerContext)
{
	DEMOGameState_Base::OnInit(ownerContext);
	m_fnt = new hgeFont("..\\..\\res\\font1.fnt");

	_tankFactory = new DEMOTank_Factory();
	_testTank = _tankFactory->generateTank(ETT_Trial);

}

void DEMOGameState_Test1::OnDestroy()
{
	if( m_fnt!=NULL )
	{
		delete m_fnt;
		m_fnt = NULL;
	}

	if(_tankFactory)
	{
		delete _tankFactory;
		_tankFactory = NULL;
	}

	if(_testTank)
	{
		delete _testTank;
		_testTank = NULL;
	}

}

bool DEMOGameState_Test1::Tick(float dt)
{
	//	temp give input directly
	//	we should use Observer Mode later
	_testTank->tick( dt );

	return false;
}

bool DEMOGameState_Test1::Render()
{
	m_fnt->printf(30,30,HGETEXT_LEFT|HGETEXT_TOP,"state test1.");
	return false;
}

bool DEMOGameState_Test1::OnInput(hgeInputEvent theEvent)
{
	if( theEvent.type == INPUT_KEYUP 
		&& theEvent.key == HGEK_ESCAPE)
	{
		m_context->GotoGameState( EDGS_TEST2);

		return false;
	}

	//	temp give input directly
	//	we should use Observer Mode later
	_testTank->OnInput( theEvent);

	return false;
}


//	
//	Class DEMOGameState_Test2
//	
DEMOGameState_Test2::DEMOGameState_Test2()
{
	m_fnt = new hgeFont("..\\..\\res\\font2.fnt");
}

DEMOGameState_Test2::~DEMOGameState_Test2()
{

}

void DEMOGameState_Test2::OnInit(DEMOGameState_Context* const ownerContext)
{
	DEMOGameState_Base::OnInit(ownerContext);

}

void DEMOGameState_Test2::OnDestroy()
{
	if( m_fnt!=NULL )
	{
		delete m_fnt;
		m_fnt = NULL;
	}
}

bool DEMOGameState_Test2::Tick(float dt)
{
	return false;
}

bool DEMOGameState_Test2::Render()
{
	m_fnt->printf(50,50,HGETEXT_LEFT|HGETEXT_TOP,"state test2.");
	return false;
}

bool DEMOGameState_Test2::OnInput(hgeInputEvent theEvent)
{
	if( theEvent.type == INPUT_KEYUP 
		&& theEvent.key == HGEK_ESCAPE)
	{
		m_context->GotoGameState( EDGS_TEST1);
	}
	return false;
}